package net.hserver.admin.system.common;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

/**
 * 返回状态码
 *
*
 * @since 2020/3/18 18:44
 */
@Getter
public enum MyCode {
    SUCCESS("成功"),
    FAILURE("失败"),

    SERVER_ERROR("服务器出错"),
    ACCESS_DENIED("无权访问"),

    NOT_LOGIN("未登录"),
    LOGIN_FAILURE("登录失败"),
    EXIST_ACCOUNT("账号被占用"),
    LOCKED_ACCOUNT("账号被冻结"),
    UNKNOWN_ACCOUNT("账号不存在"),
    ERROR_PASSWORD("密码不正确"),
    ERROR_CAPTCHA("验证码错误"),

    DATA_VERIFY_ERROR("数据校验失败"),

    NO_HANDLER_FOUND("接口不存在"),
    NOT_READABLE_PARAMETERS("无法读取参数"),
    REQUEST_METHOD_NOT_SUPPORTED("错误的请求方法"),
    DUPLICATE_KEY("唯一键重复"),
    NPE("空指针异常"),

    ;

    private String msg;

    MyCode(String msg) {
        this.msg = msg;
    }

    public MyResult toResult() {
        return MyResult.code(this);
    }

    public MyResult toResult(String message) {
        return MyResult.code(this).setMessage(message);
    }

    public MyException toException() {
        return new MyException(this.toResult());
    }

    public MyException toException(String msg) {
        if (StrUtil.isNotEmpty(msg)) {
            this.msg = msg;
        }
        return new MyException(this.toResult());
    }
}
